<%-- 
    Document   : dccr
    Created on : Apr 6, 2011, 3:37:32 PM
    Author     : Dine
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>

<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="south-street" compressed="false"/>
        <jsp:include page="WEB-INF/fragments/reportHead.html"/>
        <title>Cashmate <s:property value="#session.branch.branchname"/> - Performance and Incentives</title>
    </head>
    <body>
        <jsp:include page="WEB-INF/fragments/filters.jsp"/>
        <s:set name="status">${param.status}</s:set>

        <!-- DCCR PRIVILEGES -->
        <s:set name="dccrview">yes</s:set>
        <s:action name="query-privilege2" var="dccrprivilege" executeResult="false">
            <s:param name="pagename" value="dccr.jsp"/>
            <s:param name="moduleid" value="9"/>
        </s:action>
        <s:if test='%{!#dccrprivilege.viewable && #status != "nonviewable"}'>
            <s:set name="dccrview">no</s:set>
        </s:if>
        <s:elseif test="%{!#dccrprivilege.viewable && #parameters.status == null}">
            <s:set name="dccrview">no</s:set>
        </s:elseif>

        <!--  WEEK FILTERS -->
        <s:set name="weekview">yes</s:set>
        <s:if test="%{#session.branch.branchid == 1}">
            <s:action name="query-privilege2" var="weekprivilege1" executeResult="false">
                <s:param name="pagename" value="weekperformance.jsp"/>
                <s:param name="moduleid" value="13"/>
            </s:action>
            <s:if test='%{!#weekprivilege1.viewable && #status != "nonviewable"}'>
                <s:set name="weekview">no</s:set>
            </s:if>
            <s:elseif test="%{!#weekprivilege1.viewable && #parameters.status == null}">
                <s:set name="weekview">no</s:set>
            </s:elseif>
        </s:if>
        <s:else>
            <s:action name="query-privilege2" var="weekprivilege2" executeResult="false">
                <s:param name="pagename" value="weekperformance.jsp"/>
                <s:param name="moduleid" value="11"/>
            </s:action>
            <s:if test='%{!#weekprivilege2.viewable && #status != "nonviewable"}'>
                <s:set name="weekview">no</s:set>
            </s:if>
            <s:elseif test="%{!#weekprivilege2.viewable && #parameters.status == null}">
                <s:set name="weekview">no</s:set>
            </s:elseif>
        </s:else>

        <s:set name="weekbranchstatus">ok</s:set>
        <s:if test="%{#session.branch.branchid != 1 && #parameters.branch != null}">
            <s:set name="b" value="%{#session.branch.branchid}"/>
            <s:set name="br">${param.branch}</s:set>
            <s:if test="%{#br != #b}">
                <s:set name="weekbranchstatus">notok</s:set>
            </s:if>
        </s:if>

        <s:div id="bodyContainer">
            <s:div id="logoContainer" cssClass="ui-widget-content ui-corner-all">
                <s:include value="WEB-INF/fragments/banner.jsp">
                    <s:param name="branch" value="#session.branch.branchname" />
                </s:include>
            </s:div>
            <jsp:include page="WEB-INF/fragments/top.jsp"/>
            <jsp:include page="WEB-INF/fragments/mainMenu.jsp?menu=Perf"/>
            <s:div id="contentContainer" cssClass="ui-corner-all">
                <!--                <span id="slogan">Cashmate Performance and Incentives</span>-->
                <!--                <span id="logo"><img src="res/sandbox/CashmateLoGo.gif" alt="logo"/></span>-->
                <!--                <h1 id="contentHeader" class="ui-corner-all">
                                    <span id="level1">Daily Cash Collection Report</span>
                                </h1>-->
                <div id="menuContainer">
                    <h2 id="dccr_menu" class="ui-state-default ui-corner-top menuItem">Daily Cash Custodian Report</h2>
                    <h2 id="weekly_menu" class="ui-state-default ui-corner-top menuItem">Weekly Performance</h2>
                    <h2 id="monthly_menu" class="ui-state-default ui-corner-top menuItem">Monthly Performance</h2>
                    <h2 id="incentive_menu" class="ui-state-default ui-corner-top menuItem">Incentives</h2>
                    <h2 id="pastdue_menu" class="ui-state-default ui-corner-top menuItem">Non-moving Loans</h2>
                </div>

                <%-- DCCR CONTENT --%>
                <s:div id="dccrContent" cssClass="theContent">
                    <s:if test='%{#dccrview == "no"}'>
                        <s:include value="WEB-INF/error/unauthorized.html"/>
                    </s:if>
                    <s:else>
                        <%-- DCCR GRIDOPTS --%>
                        <sj:div id="dccrGridOpts" cssClass="gridOptsContainer ui-corner-all noaccept" draggable="true">
                            <sj:a button="true" 
                                  cssStyle="font-size:14px;" 
                                  disabled="true" 
                                  id="dccrGrid_search" 
                                  onClickTopics="searchDccrGrid">
                                Search
                            </sj:a>
                            <sj:a
                                id="reloadButton"
                                disabled="true"
                                cssStyle="font-size:14px;" 
                                onClickTopics="reloadgrid"
                                button="true">
                                Reload 
                            </sj:a>
                            <s:url action="export-excel" id="exportLink"><s:param name="type">dccr</s:param></s:url>
                            <s:a cssClass="ui-corner-all" id="exportButton" href="%{exportLink}" >Export</s:a>
                            <s:if test="%{#session.dccrgendate == null && #dccrprivilege.createable}">
                                <sj:a button="true"
                                      cssStyle="font-size:14px;"
                                      disabled="true"
                                      id="dialogDccrButton"
                                      openDialog="dccrDialog">
                                    Generate</sj:a>
                            </s:if>
                            <s:elseif test="%{#session.dccrgendate != null && #dccrprivilege.createable}">
                                <s:url action="submit-dccr" id="postlink"><s:param name="method">post</s:param></s:url>
                                <s:url action="submit-dccr" id="cancellink"><s:param name="method">cancel</s:param></s:url>

                                <sj:a button="true"
                                      id="postButton"
                                      href="%{postlink}"
                                      cssStyle="font-size:14px;"
                                      targets="result"
                                      >Post</sj:a>

                                <sj:a button="true"
                                      id="cancelpostButton"
                                      href="%{cancellink}"
                                      cssStyle="font-size:14px;"
                                      targets="result"
                                      >Cancel</sj:a>
                                <div id="result"></div>
                            </s:elseif>
                        </sj:div>

                        <%-- DCCR DIALOG --%>
                        <s:if test="%{#dccrprivilege.createable}">
                            <sj:dialog autoOpen="false" closeOnEscape="false" modal="true" id="dccrDialog" title="Generate Daily Cash Collection Report" width="500" onOpenTopics="dialogopen"
                                       showEffect="clip">
                                <div id="formResult" class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
                                    <p style="text-align:center;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                                        Please <strong>fill-up the field(s) below to generate a Daily Cash Collection Report.</strong>
                                    </p>
                                </div>

                                <s:form id="chooseDCCRForm" action="choose-dccr" cssStyle="margin:auto;">
                                    <p style="text-align:center;font-size: 10px;"><i>Fields with an (*) are required.</i></p>
                                    <sj:datepicker value="%{#session.dccrdate}" id="dccrdate" name="dccrdate" displayFormat="mm/dd/yy" label="*Date" showOn="button"/>
                                    <s:if test="%{#session.branch.branchid==1 || #session.usertype.usertypeid==1}">
                                        <s:url action="select-branches" id="selectbranches" escapeAmp="false">
                                            <s:param name="forDccr">Yes</s:param>
                                        </s:url>
                                        <sj:select href="%{selectbranches}"
                                                   id="branchselect"
                                                   name="branch"
                                                   list="branches"
                                                   label="*Branch"
                                                   cssStyle="width:235px;"
                                                   headerKey="-1"
                                                   headerValue="--Select Branch--"/>
                                    </s:if>
                                    <s:else>
                                        <s:hidden id="branchselect" value="%{#session.branch.branchid}"/>
                                    </s:else>
                                </s:form>
                                <p style="text-align:center;margin:3px 0px;">
                                    <img id="indicator" src="res/sandbox/ajax-loader.gif" alt="Loading..." style="margin:auto;display:none"/>
                                </p>
                                <hr/>
                                <sj:a cssClass="ui-state-default dialogbutton" id="cancelButton"
                                      cssStyle="float:right;font-size:14px;"
                                      button="true"
                                      onClickTopics="cancelSubmitClick">
                                    Cancel</sj:a>
                                <sj:submit cssClass="ui-state-default dialogbutton" id="submitButton"
                                           cssStyle="float:right;font-size:14px;"
                                           value="Submit"
                                           targets="formResult"
                                           button="true"
                                           onBeforeTopics="chooseBefore"
                                           effect="highlight"
                                           formIds="chooseDCCRForm"
                                           effectDuration="300"/>

                                <br />
                                <s:div id="confirmGen" cssStyle="display:none;float:right;">
                                    <s:url action="confirm-gen" id="confirm"/>
                                    <sj:submit button="true"
                                               value="Yes"
                                               targets="formResult"
                                               indicator="indicator"
                                               href="%{confirm}"
                                               onBeforeTopics="yesClickBefore"
                                               cssStyle="font-size:14px;"
                                               />
                                    <sj:a value="No"
                                          button="true"
                                          cssStyle="font-size:14px;"
                                          onClickTopics="noClick">No</sj:a> 
                                </s:div>
                            </sj:dialog>
                        </s:if>

                        <s:url action="grid-dccr" id="remoteurl"/>
                        <s:if test="%{#dccrprivilege.editable}">
                            <s:url action="edit-dccr" id="editurl"/>
                        </s:if>
                        <s:if test="%{#session.dccrgendate == null && #session.dccrbranchname == null }">
                            <s:include value="WEB-INF/fragments/dccrcontent.jsp"/>
                        </s:if>
                        <s:if test="%{#session.dccrgendate != null && #session.dccrbranchname != null}">
                            <s:include value="WEB-INF/fragments/dccrcontentgen.jsp"/>
                            <script type="text/javascript">
                                firewarn=true;
                            </script>
                        </s:if>
                    </s:else>
                </s:div>

                <%--WEEK CONTENT--%>
                <s:div id="weekContent" cssClass="theContent">
                    <s:if test='%{#weekview == "no" || #weekbranchstatus == "notok"}'>
                        <s:include value="WEB-INF/error/unauthorized.html"/>
                    </s:if>
                    <s:else>
                        <%-- WEEK GRIDOPTS --%>
                        <sj:div id="weekGridOpts" cssClass="gridOptsContainer ui-corner-all noaccept ui-widget-content" draggable="true">
                            <sj:a  button="true"
                                   cssStyle="font-size:14px;" 
                                   openDialog="weekPerfDialog">
                                Choose</sj:a>
                            <s:if test="%{#parameters.branch != null && #parameters.date !=null}">
                                <sj:submit button="true" 
                                           cssStyle="font-size:14px;" 
                                           disabled="true"
                                           id="weekPerfGrid_search" 
                                           onClickTopics="searchWeekGrid"
                                           value="Search"/>
                                <s:url action="export-excel" id="exportLink"><s:param name="type">week</s:param></s:url>
                                <s:a cssClass="ui-corner-all" id="exportButton" href="%{exportLink}" >Export</s:a>
                            </s:if>
                        </sj:div>

                        <%-- WEEK DIALOG --%>
                        <sj:dialog autoOpen="false" closeOnEscape="false" modal="true" id="weekPerfDialog" title="Choose Weekly Performance Rating" width="500" showEffect="slide" openTopics="dialogopen" hideEffect="none">
                            <div id="weekformResult" class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
                                <p style="text-align:center;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                                    Please <strong>select a cut-off date to display weekly performance.</strong>
                                </p>
                            </div>
                            <s:form action="choose-perf" cssStyle="margin:auto;" id="choosePerf">
                                <s:hidden name="type" value="week"/>
                                <s:url id="dccrurl" action="select-cutoff"/>
                                <sj:select
                                    onCompleteTopics="cutoffLoadComplete"
                                    label="Cut-Off Date"
                                    href="%{dccrurl}"
                                    id="cutoffSelect"
                                    name="cutoffDate"
                                    list="cutoffMap"
                                    />
                            </s:form>
                            <hr />
                            <sj:a cssClass="ui-state-default" id="weekCancelButton"
                                  cssStyle="float:right;font-size:14px;"
                                  button="true"
                                  onClickTopics="cancelweekSubmitClick">
                                Cancel</sj:a>
                            <sj:submit cssClass="ui-state-default" id="weekSubmitButton"
                                       cssStyle="float:right;font-size:14px;"
                                       value="Submit"
                                       button="true"
                                       effect="highlight"
                                       formIds="choosePerf"
                                       effectDuration="300"/>
                        </sj:dialog>
                        <s:if test="%{#parameters.branch != null && #parameters.date !=null}">
                            <s:url action="grid-weekperf" id="remoteurl" escapeAmp="false">
                                <s:param name="date" value="%{#parameters.date}"/>
                                <s:param name="branch" value="%{#parameters.branch}"/>
                            </s:url>
                            <s:action name="select-branches" executeResult="false" var="br">
                                <s:param name="forPerf" value="%{#parameters.branch}"/>
                            </s:action>
                            <s:bean name="com.cashmate.utilities.DCCRDate" var="date">
                                <s:param name="date" value="%{#parameters.date}"/>
                            </s:bean>
                            <sjg:grid
                                id="performanceGrid"
                                caption="%{#br.branchname} Weekly Performance Rating for %{#date.paymentday1} to %{#date.cutoff}"
                                dataType="json"
                                href="%{remoteurl}"
                                gridModel="gridModel"
                                pagerButtons="false"
                                pagerInput="false"
                                rowNum="-1"
                                loadingText="Requesting Data..."
                                width="1260"
                                shrinkToFit="false"
                                pager="true"
                                hoverrows="true"
                                rownumbers="true"
                                autoencode="true"
                                viewrecords="true"
                                navigator="true"
                                navigatorAdd="false"
                                navigatorDelete="false"
                                navigatorEdit="false"
                                navigatorSearch="true"
                                navigatorView="true"
                                onGridCompleteTopics="weekperformanceGridComplete"
                                >

                                <sjg:gridColumn name="areacode"
                                                index="areacode"
                                                title="Area"
                                                sortable="true"
                                                search="true"
                                                align="center"
                                                />
                                <sjg:gridColumn name="rating"
                                                index="rating"
                                                title="Rating"
                                                sortable="true"
                                                search="false"
                                                align="center"
                                                />

                                <sjg:gridColumn name="cutoffdue"
                                                index="cutoffdue"
                                                title="Due"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="overdue"
                                                index="overdue"
                                                title="Overdue"
                                                sortable="true"
                                                formatter="currency"
                                                search="false"
                                                align="center"
                                                />

                                <sjg:gridColumn name="dueplusod"
                                                index="dueplusod"
                                                title="Payment for DUE+OD"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="totaladvance"
                                                index="totaladvance"
                                                title="Payment for Advance"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="debitedpayment"
                                                index="debitedpayment"
                                                title="Debited Payment"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="computedtotalpayment"
                                                index="computedtotalpayment"
                                                title="Total Payment"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="totalcutoffcollection"
                                                index="totalcutoffcollection"
                                                title="Total Collection"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="pngenerated"
                                                index="pngenerated"
                                                title="PN Generated"
                                                sortable="true"
                                                search="false"
                                                formatter="currency"
                                                align="center"
                                                />

                                <sjg:gridColumn name="newacct"
                                                index="newacct"
                                                title="New Accounts"
                                                sortable="true"
                                                search="false"
                                                align="center"
                                                />

                                <sjg:gridColumn name="totacctrel"
                                                index="totacctrel"
                                                title="Accounts Released"
                                                sortable="true"
                                                search="false"
                                                align="center"
                                                />
                                <sjg:gridColumn name="pnna"
                                                index="pnna"
                                                title="PN N/A"
                                                sortable="true"
                                                search="false"
                                                align="center"
                                                />
                            </sjg:grid>
                        </s:if>
                        <s:else>
                            <h3 style="width: 500px;margin:150px auto;text-align: center;">Press the choose button to select a cut-off period and branch.</h3>
                        </s:else>
                    </s:else>
                </s:div>          
            </s:div>
            <%--<jsp:include page="WEB-INF/fragments/bottom.jsp"/>--%>
        </s:div>
    </body>
</html>
